package Merlion.SCM.entity;

import Merlion.MRP.entity.PlannedDailyDemandEntity;
import Merlion.MRP.entity.ReservationEntity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

@Entity
public class InventoryBatchEntity implements Serializable {

    //common attributes
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @ManyToOne
    private InventoryEntity item;
    private Long itemId;
    @ManyToOne
    private WarehouseEntity warehouse;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date expiryDate;
    private int initialQty;
    private int inHandQty;
    private int reservedQty;
    private String remarks;
    private boolean deleted;
    //
    //product batch attributes
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date mfgDate;
    @OneToOne(mappedBy = "productBatch")
    private PlannedDailyDemandEntity plannedDailyDemand;

    //
    //material batch attributes
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date receiptDate;
    @OneToMany(mappedBy = "inventoryBatch")
    private List<ReservationEntity> reservationEntities;

    public InventoryBatchEntity() {
    }

    public void createProductBatch(InventoryEntity item, Date expiryDate, int initialQty, int inHandQty, int reservedQty, String remarks, Date mfgDate, PlannedDailyDemandEntity plannedDailyDemand) {
        this.item = item;
        this.itemId = item.getId();
        this.expiryDate = expiryDate;
        this.initialQty = initialQty;
        this.inHandQty = inHandQty;
        this.reservedQty = reservedQty;
        this.remarks = remarks;
        this.deleted = false;
        this.mfgDate = mfgDate;
        this.plannedDailyDemand = plannedDailyDemand;
    }

    public void createMaterialBatch(InventoryEntity item, Date expiryDate, int initialQty, int inHandQty, int reservedQty, String remarks, Date receiptDate) {
        this.item = item;
        this.itemId = item.getId();
        this.expiryDate = expiryDate;
        this.initialQty = initialQty;
        this.inHandQty = inHandQty;
        this.reservedQty = reservedQty;
        this.remarks = remarks;
        this.deleted = false;
        this.receiptDate = receiptDate;
    }

    
    
    public ProductEntity getProduct() {
        ProductEntity product = (ProductEntity) item;
        return product;
    }

    public Date getReceiptDate() {
        return receiptDate;
    }

    public void setReceiptDate(Date receiptDate) {
        this.receiptDate = receiptDate;
    }

    public Long getItemId() {
        return itemId;
    }

    public void setItemId(Long itemId) {
        this.itemId = itemId;
    }

    
    public void setProduct(ProductEntity item) {
        this.item = (InventoryEntity) item;
    }

    public MaterialEntity getMaterial() {
        MaterialEntity material = (MaterialEntity) item;
        return material;
    }

    public void setMaterial(MaterialEntity item) {
        this.item = (MaterialEntity) item;
    }

    public PlannedDailyDemandEntity getPlannedDailyDemand() {
        return plannedDailyDemand;
    }

    public void setPlannedDailyDemand(PlannedDailyDemandEntity plannedDailyDemand) {
        this.plannedDailyDemand = plannedDailyDemand;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public List<ReservationEntity> getReservationEntities() {
        return reservationEntities;
    }

    public void setReservationEntities(List<ReservationEntity> reservationEntities) {
        this.reservationEntities = reservationEntities;
    }

    public Date getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    public int getInitialQty() {
        return initialQty;
    }

    public void setInitialQty(int initialQty) {
        this.initialQty = initialQty;
    }

    public Date getMfgDate() {
        return mfgDate;
    }

    public void setMfgDate(Date mfgDate) {
        this.mfgDate = mfgDate;
    }

    public InventoryEntity getitem() {
        return item;
    }

    public void setitem(InventoryEntity item) {
        this.item = item;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public InventoryEntity getItem() {
        return item;
    }

    public void setItem(InventoryEntity item) {
        this.item = item;
    }

    public int getInHandQty() {
        return inHandQty;
    }

    public void setInHandQty(int inHandQty) {
        this.inHandQty = inHandQty;
    }

    public int getReservedQty() {
        return reservedQty;
    }

    public void setReservedQty(int reservedQty) {
        this.reservedQty = reservedQty;
    }

    public WarehouseEntity getWarehouse() {
        return warehouse;
    }

    public void setWarehouse(WarehouseEntity warehouse) {
        this.warehouse = warehouse;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InventoryBatchEntity)) {
            return false;
        }
        InventoryBatchEntity other = (InventoryBatchEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.itemBatchEntity[ id=" + id + " ]";
    }
}
